package com.controller.system.system;

import com.entity.system.SystemGlobalConfig;
import com.service.system.system.SystemConfigService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/system")
public class SystemConfigController {

    @Autowired
    SystemConfigService systemConfigService;

    /**
     * 查询系统配置列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/findSystenConfigList",method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public Map<String,Object> findSystenConfigList(HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        map.put("pageSize",request.getParameter("pageSize"));
        map.put("pageNum",request.getParameter("pageNum"));
        if(StringUtils.isNotEmpty(request.getParameter("configName"))){
            map.put("configName","%"+request.getParameter("configName")+"%");
        }
        if(StringUtils.isNotEmpty(request.getParameter("state"))){
            map.put("state",request.getParameter("state"));
        }
        return systemConfigService.findSystenConfigList(map);
    }

    /**
     * 修改系统配置
     * @param systemGlobalConfig
     * @return
     */
    @RequestMapping(value = "/updateConfig",method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public Map<String,Object> updateConfig(SystemGlobalConfig systemGlobalConfig){
        return systemConfigService.updateConfig(systemGlobalConfig);
    }

    /**
     * 添加系统配置
     * @param systemGlobalConfig
     * @return
     */
    @RequestMapping(value = "/addConfig",method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public Map<String,Object> addConfig(SystemGlobalConfig systemGlobalConfig){
        return systemConfigService.addConfig(systemGlobalConfig);
    }
}
